<template>
	<view>
		<view class="cu-bar bg-white search fixed" >
		<view class="search-form round">
			<text class="cuIcon-search"></text>
			<input :adjust-position="false" type="text" v-model="searchvalue" placeholder="请输入考试名称" confirm-type="search" />
		</view>
		<view class="action"><button @click="doSearch" class="cu-btn bg-green shadow-blur round">搜索</button></view>
	</view>
	<view :style="[{ 'margin-top': 70  + 'px' }]">
			<mescroll-uni :down="downOption" @down="downCallback" :up="upOption" @up="upCallback" @init="mescrollInit">
			<view class="cu-list menu" v-for="(item, index) in examdata" :key="item.id">
				<view class="cu-item ">
					<view class="content padding-tb-sm">
						<view>
							<text class="text-blue margin-right-xs">试卷名称:</text>
							{{ item.exam.name }}
						</view>
						<view class="text-gray text-sm">
							<text class="cuIcon-edit  text-blue margin-right-xs">试卷标题:</text>
							{{ item.exam.title }}
						</view>
						<view class="text-gray text-sm">
							<text class="cuIcon-timefill text-blue margin-right-xs">开始时间:</text>
							{{ item.exam.stime }}
						</view>
						<view class="text-gray text-sm">
							<text class="cuIcon-time text-blue margin-right-xs">结束时间:</text>
							{{ item.exam.etime }}
						</view>
						<view class="text-gray text-sm">
							<text class="cuIcon-sort text-blue margin-right-xs">所属科目:</text>
							{{ item.subpro.subname }}/{{ item.subpro.proname }}
						</view>
					</view>
					<view class="action">
						<button class="cu-btn round bg-green shadow" @click="doExam(item)">
							<text class="cuIcon-notice"></text>
							查看成绩
						</button>
					</view>
				</view>
			</view>
				<ShowNull :isConnected="isConnected"></ShowNull>
		</mescroll-uni>
		</view>
	</view>
</template>

<script>
// 引入mescroll-uni组件
import MescrollUni from 'mescroll-uni/mescroll-uni.vue';
import uniList from '@/components/uni-list/uni-list.vue';
import uniListItem from '@/components/uni-list-item/uni-list-item.vue';
import ShowNull from '@/components/shownull.vue';
import { mapState } from 'vuex';
export default {
	computed: mapState(['user', 'hasLogin']),
	components: {
		MescrollUni,
		uniList,
		uniListItem,
		ShowNull
	},
	data() {
		return {
			isConnected: true,
			modalName: null,
			modalContent: '',
			CustomBar: this.CustomBar,
			examdata: [],
			scrollTop: 0,
			InputBottom: 0,
			old: {
				scrollTop: 0
			},
			searchvalue: '',
			searchval: 'name',
			todata: {},
			curentitem: {
				doExamSize: '',
				exam: '',
				maxFraction: '',
				subpro: {}
			},
			mescroll: null, //mescroll实例对象
			// 下拉刷新的配置
			downOption: {
				use: true, // 是否启用下拉刷新; 默认true
				auto: true // 是否在初始化完毕之后自动执行下拉刷新的回调; 默认true
			},
			// 上拉加载的配置
			upOption: {
				use: true, // 是否启用上拉加载; 默认true
				auto: false, // 是否在初始化完毕之后自动执行上拉加载的回调; 默认true
				isLock: false, // 是否锁定上拉加载 (可用于不触发upCallback,只保留回到顶部按钮的场景)
				page: {
					num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
					size: 10 // 每页数据的数量,默认10
				},
				noMoreSize: 3, // 配置列表的总数量要大于等于5条才显示'-- END --'的提示
				empty: {
					tip: '暂无相关数据'
				}
			},
			// 列表数据
			dataList: []
		};
	},
	// 必须注册滚动到底部的事件,使上拉加载生效
	onReachBottom() {
		this.mescroll && this.mescroll.onReachBottom();
	},
	// 必须注册列表滚动事件,使下拉刷新生效
	onPageScroll(e) {
		this.mescroll && this.mescroll.onPageScroll(e);
	},
	methods: {
		hideModal() {
			this.modalName = null;
			this.todata = {};
		},
		initData: function() {
			if (this.hasLogin) {
				var data = {
					workno: this.user.workno,
					searchvalue: this.searchvalue,
					searchval: this.searchval
				};
				data = encodeURI(JSON.stringify(data));
				///examonline/hasExam
				uni.request({
					url: '/examonline/mobile/preCXCJ',
					data: {
						data
					},
					dataType: 'GET',
					success: res => {
						let resdata = JSON.parse(res.data);
						this.examdata = resdata.data;
						if (this.examdata.length == 0) {
							this.isConnected = false;
						}
					}
				});
			}
		},
		doExam: function(item) {
			if (this.hasLogin) {
				this.modalName = 'DialogModal2';
				this.curentitem = item;
			} else {
				uni.showToast({
					title: '无法获取登陆信息，请重新登陆！',
					duration: 2000
				});
			}
		},
		// mescroll组件初始化的回调,可获取到mescroll对象
		mescrollInit(mescroll) {
			this.mescroll = mescroll;
		},
		/*下拉刷新的回调, 有三种处理方式: */
		downCallback(mescroll) {
			mescroll.endSuccess();
		},
		/*上拉加载的回调*/
		upCallback(mescroll) {
			mescroll.endByPage(1, 10);
			console.log(mescroll);
		},doSearch: function() {
			this.initData();
		}
	},onReady() {
		this.initData();
			/* if (this.hasLogin) {
				this.initData();
			} else {
				uni.navigateTo({
					url: '../login/login'
				});
			} */
	}
};
</script>

<style></style>
